using System;

namespace Nairo.Parser
{
	public struct Location : IEquatable<Location>
	{
		int line;
		int column;

		public Location(int line, int column)
		{
			this.line = line;
			this.column = column;
		}
		
		public int Line {
			get { return line; }
			set { line = value; }
		}
		
		public int Column {
			get { return column; }
			set { column = value; }
		}
		
		public static Location Null
		{
			get { return new Location(-1, -1); }
		}
		
		
		#region Equals and GetHashCode implementation		
		public override bool Equals(object obj)
		{
			if (obj is Location)
				return Equals((Location)obj);  // use Equals method below
			else
				return false;
		}
		
		public bool Equals(Location other)
		{
			// add comparisions for all members here
			return (this.column == other.column) &&
				(this.line == other.line);
		}
		
		public override int GetHashCode()
		{
			// combine the hash codes of all members here (e.g. with XOR operator ^)
			return line.GetHashCode() ^ column.GetHashCode();
		}
		
		public static bool operator ==(Location lhs, Location rhs)
		{
			return lhs.Equals(rhs);
		}
		
		public static bool operator !=(Location lhs, Location rhs)
		{
			return !(lhs.Equals(rhs)); // use operator == and negate result
		}
		
		public static bool operator >(Location lhs, Location rhs)
		{
			if (lhs.line == rhs.line) {
				return (lhs.column > rhs.column);
			} else {
				return (lhs.line > rhs.line);
			}
		}
		
		public static bool operator <(Location lhs, Location rhs)
		{
			if (lhs.line == rhs.line) {
				return (lhs.column < rhs.column);
			} else {
				return (lhs.line < rhs.line);
			}
		}
		#endregion
	}
}
